package achi.community.irla.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import achi.community.irla.database.Crypto;

@Entity
public class Users implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String date_registred;
    //@Column(nullable = false)
    private String firstName;
    //@Column(nullable = false)
    private String lastName;
    private String email;
    private String username;
    private String password;
    private String avatar;

    @OneToMany(mappedBy = "uuser", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Friends> friends;

    @OneToMany(mappedBy = "friend", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Friends> friendedMe;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Messages> messages;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Achievements_completed> achievements_completed;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Achievements_comments> achievements_comments;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Achievements_target> achievements_target;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Achievements_suggested> achievements_suggested;

   // @ManyToMany(mappedBy = "friends", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
   // private List<Users> friends;
    
    //@OneToMany(mappedBy = "friendedMe", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    //private List<Users> friendedMe;

    /**
     * only used to implement Serializable.
     */
    public Users() {}

    /**
     * creates a new Users entity
     * @param fname value of the firstName column
     * @param lname value of the lastName column
     * @param email value of the email column
     * @param address value of the address column
     */
    public Users(String firstName, String lastName, String email, String username, String password, String avatar) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.username = username;
        this.password = password;
        this.avatar = avatar;
        date_registred = (new Date()).toString();
    }

    public void setAchievements_target(List<Achievements_target> achievements_target) {
        this.achievements_target = achievements_target;
    }

    public void setAchievements_completed(List<Achievements_completed> achievements_completed) {
        this.achievements_completed = achievements_completed;
    }

    public void setAchievements_suggested(List<Achievements_suggested> achievements_suggested) {
        this.achievements_suggested = achievements_suggested;
    }

    public void setAchievements_comments(List<Achievements_comments> achievements_comments) {
        this.achievements_comments = achievements_comments;
    }

    public List<Achievements_target> getAchievements_target() {
        return achievements_target;
    }

    public List<Achievements_suggested> getAchievements_suggested() {
        return achievements_suggested;
    }

    public List<Achievements_completed> getAchievements_completed() {
        return achievements_completed;
    }

    public List<Achievements_comments> getAchievements_comments() {
        return achievements_comments;
    }

    public void setFriendedMe(List<Friends> friendedMe) {
        this.friendedMe = friendedMe;
    }

    public List<Friends> getFriendedMe() {
        return friendedMe;
    }

    public List<Friends> getFriends() {
        return friends;
    }

    public void setFriends(List<Friends> friends) {
        this.friends = friends;
    }

    public void setMessages(List<Messages> messages) {
        this.messages = messages;
    }

    public List<Messages> getMessages() {
        return messages;
    }

    public String getAvatar() {
        return avatar;
    }

    public String getDate_registred() {
        return date_registred;
    }

    public String getEmail() {
        return email;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return username;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setPassword(String password) {
        //Crypto.byteArrayToHexString(Crypto.computeHash(password));
        this.password = password;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setDate_registred(String date_registred) {
        this.date_registred = date_registred;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

/**
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
* */
    @Override
    public String toString() {
        return "achi.community.irla.Users[id=" + id + "]";
    }
 
}
